package com.jy.oms.framework.asyn.task.constants;

import com.jy.oms.framework.asyn.task.exception.TaskConfigException;
import org.redisson.api.RateIntervalUnit;

import java.util.concurrent.TimeUnit;

/**
 * 时间单位
 *
 * @author liuquan
 */
public enum TimeUnitEnum {

    Second, Minute, Hour, Day, Month;

    public static TimeUnit toTimeUnit(TimeUnitEnum timeUnit) {
        switch (timeUnit) {
            case Second:
                return TimeUnit.SECONDS;
            case Minute:
                return TimeUnit.MINUTES;
            case Hour:
                return TimeUnit.HOURS;
            case Day:
                return TimeUnit.DAYS;
        }

        throw new TaskConfigException("不支持时间单位转化");
    }

    public static RateIntervalUnit toRateIntervalUnit(TimeUnitEnum timeUnit) {
        switch (timeUnit) {
            case Second:
                return RateIntervalUnit.SECONDS;
            case Minute:
                return RateIntervalUnit.MINUTES;
            case Hour:
                return RateIntervalUnit.HOURS;
            case Day:
                return RateIntervalUnit.DAYS;
        }

        throw new TaskConfigException("不支持时间单位转化");
    }
}
